import React, { Component } from "react";

import { withRouter } from "react-router-dom";

class Search extends Component {

    back = () => {
        this.props.history.goBack()
      }
      forward = () => {
        this.props.history.goForward()
      }
      go = () => {
        this.props.history.go(-2)
      }

    render() {
        return (
            <div>
               <h2>React Router Demo</h2>
               <div>
                   <button onClick={this.back}>回退</button>
                   <button onClick={this.forward}>前进</button>
                   <button onClick={this.go}>go</button>
                </div>
            </div>
        )
    }
}

export default withRouter(Search)

//withRouter可以加工一般组件，让一般组件具备路由组件所特有的API
//withRouter的返回值是一个新组件